﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DimensionalMeasurement
{
    public partial class FormCheck : Form
    {
        public delegate void ReadStr(string[] str);
        string str = "";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="s"></param>
        /// <param name="bOnlyCount">是否单独计数</param>
        /// <param name="bOnlyJudge">是否单独判断</param>
        /// <param name="LL">来料不良选项</param>
        /// <param name="CancelJudgment">取消判断</param>
        /// <param name="type">类型</param>
        public FormCheck(string s, bool bOnlyCount, bool bOnlyJudge, bool LL, bool CancelJudgment, bool chart, bool Arc, string type)
        {
            InitializeComponent();
            lTitle.Text = $"{type}计算方式";
            this.str = s;
            radioButton1.Text = "左上--右上";
            radioButton2.Text = "左下--右下";
            radioButton3.Text = "左上--左下";
            radioButton4.Text = "右上--右下";
            cbOnlyCount.Visible = false;
            cbOnlyJudge.Visible = false;
            cbArc.Visible = false;
            radioButton5.Visible = false;//目前只有肩宽使用
            if (Regex.IsMatch(type, "左肩宽"))
            {
                lTitle.Text = "左肩宽计算方式";
                radioButton1.Text = "极耳左竖边中点--极片左竖边中点";
                radioButton2.Text = "极耳左竖边与极耳横边交点--极片左竖边中点";
                radioButton3.Text = "极耳左竖边与带料横边交点--极片左竖边中点";
                radioButton4.Text = "极耳左竖边与极片左横边交点--极片左竖边中点";
                radioButton5.Visible = true;
                radioButton5.Text = "极耳中点--极片左竖边中点";

                cbOnlyCount.Text = "左右肩宽同时计数";
                cbOnlyJudge.Text = "左右肩宽同时判断";
                cbOnlyCount.Visible = true;
                cbOnlyJudge.Visible = true;
                if (bOnlyCount) cbOnlyCount.Checked = true;
                if (bOnlyJudge) cbOnlyJudge.Checked = true;
                cbCancelJudgment.Checked = CancelJudgment;
                cbChart.Checked = chart;
                cbArc.Visible = true; cbArc.Checked = Arc;
            }

            if (Regex.IsMatch(type, "右肩宽"))
            {
                lTitle.Text = "右肩宽计算方式";
                radioButton1.Text = "极耳右竖边中点--极片右竖边中点";
                radioButton2.Text = "极耳右竖边与极耳横边交点--极片右竖边中点";
                radioButton3.Text = "极耳右竖边与带料横边交点--极片右竖边中点";
                radioButton4.Text = "极耳右竖边与极片右横边交点--极片右竖边中点";
                radioButton5.Visible = true;
                radioButton5.Text = "极耳中点--极片右竖边中点";
                cbOnlyCount.Text = "左右肩宽同时计数";
                cbOnlyJudge.Text = "左右肩宽同时判断";
                cbOnlyCount.Visible = true;
                cbOnlyJudge.Visible = true;
                if (bOnlyCount) cbOnlyCount.Checked = true;
                if (bOnlyJudge) cbOnlyJudge.Checked = true;
                cbCancelJudgment.Checked = CancelJudgment;
                cbChart.Checked = chart;
                cbArc.Visible = true; cbArc.Checked = Arc;

            }
            if (Regex.IsMatch(type, "极耳宽"))
            {
                lTitle.Text = "极耳宽计算方式";
                radioButton1.Text = "极耳左竖边中点--极耳右竖边中点";
                radioButton2.Text = "极耳左竖边与极耳横边交点--极耳右竖边与极耳横边交点";
                radioButton3.Text = "极耳左竖边与带料横边交点--极耳右竖边与带料横边交点";
                radioButton4.Text = "极耳左竖边与极片横边交点--极耳右竖边与极片横边交点";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "极耳高"))
            {
                lTitle.Text = "极耳高计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "陶瓷高"))
            {
                lTitle.Text = "陶瓷高计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "带料高"))
            {
                lTitle.Text = "带料高计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "总宽"))
            {
                lTitle.Text = "总宽计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "涂布高"))
            {
                lTitle.Text = "涂布高计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "对角线"))
            {
                lTitle.Text = "对角线计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "左上相机角度"))
            {
                lTitle.Text = "相机角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右上相机角度"))
            {
                lTitle.Text = "相机角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "左下相机角度"))
            {
                lTitle.Text = "相机角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右下相机角度"))
            {
                lTitle.Text = "相机角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }

            if (Regex.IsMatch(type, "极片头宽") || Regex.IsMatch(type, "极片尾宽"))
            {
                cbOnlyCount.Text = "极片头尾宽同时计数";
                cbOnlyJudge.Text = "极片头尾宽同时判断";
                cbOnlyCount.Visible = true;
                cbOnlyJudge.Visible = true;
                if (bOnlyCount) cbOnlyCount.Checked = true;
                if (bOnlyJudge) cbOnlyJudge.Checked = true;
            }
            if (Regex.IsMatch(type, "极片头宽"))
            {
                cbCancelJudgment.Checked = CancelJudgment;
                cbChart.Checked = chart;
            }
            if (Regex.IsMatch(type, "极片尾宽"))
            {
                cbCancelJudgment.Checked = CancelJudgment;
                cbChart.Checked = chart;
            }
            if (Regex.IsMatch(type, "极片头长"))
            {
                cbCancelJudgment.Checked = CancelJudgment;
                cbOnlyJudge.Visible = true;
                if (bOnlyJudge) cbOnlyJudge.Checked = true;
            }
            if (Regex.IsMatch(type, "极片尾长"))
            {
                cbCancelJudgment.Checked = CancelJudgment;
                cbOnlyJudge.Visible = true;
                if (bOnlyJudge) cbOnlyJudge.Checked = true;
            }

            if (Regex.IsMatch(type, "左上V角度"))
            {
                lTitle.Text = "V角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右上V角度"))
            {
                lTitle.Text = "V角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "左下V角度"))
            {
                lTitle.Text = "V角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右下V角度"))
            {
                lTitle.Text = "V角度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }

            if (Regex.IsMatch(type, "左上V深度") || Regex.IsMatch(type, "右上V深度"))
            {
                cbOnlyJudge.Text = "左上右上V深度同时判断"; if (bOnlyJudge) cbOnlyJudge.Checked = true; cbOnlyJudge.Visible = true;
            }
            if (Regex.IsMatch(type, "左下V深度") || Regex.IsMatch(type, "右下V深度"))
            {
                cbOnlyJudge.Text = "左下右下V深度同时判断"; if (bOnlyJudge) cbOnlyJudge.Checked = true; cbOnlyJudge.Visible = true;
            }
            if (Regex.IsMatch(type, "左上V深度"))
            {
                lTitle.Text = "V深度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右上V深度"))
            {
                lTitle.Text = "V深度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "左下V深度"))
            {
                lTitle.Text = "V深度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右下V深度"))
            {
                lTitle.Text = "V深度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }

            if (Regex.IsMatch(type, "左上V宽度"))
            {
                radioButton1.Text = "V角斜边与极片横边交点--极片竖边";
                lTitle.Text = "V宽度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右上V宽度"))
            {
                radioButton1.Text = "V角斜边与极片横边交点--极片竖边";
                lTitle.Text = "V宽度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "左下V宽度"))
            {
                radioButton1.Text = "V角斜边与极片横边交点--极片竖边";
                lTitle.Text = "V宽度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            if (Regex.IsMatch(type, "右下V宽度"))
            {
                radioButton1.Text = "V角斜边与极片横边交点--极片竖边";
                lTitle.Text = "V宽度计算方式";
                cbCancelJudgment.Checked = CancelJudgment;
            }
            cbLL.Checked = LL;//来料不良选项
        }

        public event ReadStr ReadStrEvent;
        private void bLogin_Click(object sender, EventArgs e)
        {
            string[] str = new string[7];
            if (radioButton1.Checked)
            {
                str[0] = radioButton1.Text;
            }
            if (radioButton2.Checked)
            {
                str[0] = radioButton2.Text;
            }
            if (radioButton3.Checked)
            {
                str[0] = radioButton3.Text;
            }
            if (radioButton4.Checked)
            {
                str[0] = radioButton4.Text;
            }
            if (radioButton5.Checked)
            {
                str[0] = radioButton5.Text;
            }
            str[1] = cbOnlyCount.Checked.ToString();
            str[2] = cbOnlyJudge.Checked.ToString();
            str[3] = cbLL.Checked.ToString();
            str[4] = cbCancelJudgment.Checked.ToString();
            str[5] = cbChart.Checked.ToString();
            str[6] = cbArc.Checked.ToString();
            ReadStrEvent(str);
            Close();
        }

        private void FormCheck_Load(object sender, EventArgs e)
        {

            switch (str)
            {
                case "左上--右上": radioButton1.Checked = true; break;
                case "左下--右下": radioButton2.Checked = true; break;
                case "左上--左下": radioButton3.Checked = true; break;
                case "右上--右下": radioButton4.Checked = true; break;

                case "极耳左竖边中点--极片左竖边中点": radioButton1.Checked = true; break;
                case "极耳左竖边与极耳横边交点--极片左竖边中点": radioButton2.Checked = true; break;
                case "极耳左竖边与带料横边交点--极片左竖边中点": radioButton3.Checked = true; break;
                case "极耳左竖边与极片左横边交点--极片左竖边中点": radioButton4.Checked = true; break;
                case "极耳中点--极片左竖边中点": radioButton5.Checked = true; break;

                case "极耳右竖边中点--极片右竖边中点": radioButton1.Checked = true; break;
                case "极耳右竖边与极耳横边交点--极片右竖边中点": radioButton2.Checked = true; break;
                case "极耳右竖边与带料横边交点--极片右竖边中点": radioButton3.Checked = true; break;
                case "极耳右竖边与极片右横边交点--极片右竖边中点": radioButton4.Checked = true; break;
                case "极耳中点--极片右竖边中点": radioButton5.Checked = true; break;

                case "极耳左竖边中点--极耳右竖边中点": radioButton1.Checked = true; break;
                case "极耳左竖边与极耳横边交点--极耳右竖边与极耳横边交点": radioButton2.Checked = true; break;
                case "极耳左竖边与带料横边交点--极耳右竖边与带料横边交点": radioButton3.Checked = true; break;
                case "极耳左竖边与极片横边交点--极耳右竖边与极片横边交点": radioButton4.Checked = true; break;

                case "V角斜边与极片横边交点--极片竖边": radioButton1.Checked = true; break;
                default:
                    break;
            }
        }

        private void pTitle_MouseDown(object sender, MouseEventArgs e)
        {
            Tool.FormMove(Handle);
        }

    }
}
